<?php

namespace slinks\extensions\redbean;

use slinks\core\Config\Resource\FileResource;
use slinks\common\io\AnnotationReader;
use slinks\core\dependencyInjectionExt\extension\Extension;
use slinks\core\DependencyInjection\ContainerBuilder;

/**
 * Configures Redbean
 * @author Navid Mitchell
 */
class RedbeanExtension extends Extension {

    /**
     * Configures redbean facade
     *
     * Usage example:
     *
     *      <redbean:config dsn="" freeze=""/>
     *
     * @param array $config An array of configuration settings
     * @param ContainerBuilder $container A ContainerBuilder instance
     */
    public function configLoad($config, ContainerBuilder $container) {   
        if(isset($config['rbIncludePath'])){
            require_once $config['rbIncludePath'];

            if(isset($config['dsn'])){
                \R::setup($config['dsn']); 
            }

            if(isset($config['freeze'])){
                \R::freeze($config['freeze']);
            }
        }
    }

    /**
     * Returns the base path for the XSD files.
     *
     * @return string The XSD base path
     */
    public function getXsdValidationBasePath() {
        return __DIR__ . '/resources/schema';
    }

    /**
     * Returns the namespace to be used for this extension (XML namespace).
     *
     * @return string The XML namespace
     */
    public function getNamespace() {
        return 'http://www.mitchellsoftware.net/schema/dic/redbean';
    }

    /**
     * Returns the recommended alias to use in XML.
     *
     * This alias is also the mandatory prefix to use when using YAML.
     *
     * @return string The alias
     */
    public function getAlias() {
        return 'redbean';
    }

}

